package com.song;

import com.song.ioc.*;
import com.song.ioc.循环依赖.A;
import com.song.ioc.循环依赖.B;
import com.song.my.imports.service.IImportServiceTest;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;

/**
 * @Description: SpringTest：类描述
 * @author: songzhangyong
 * @Date: 2019/10/27 10:52
 */
public class SpringTest {


	public static void main(String[] args) {
		/**
		 *
		 * Autowired 先通过byType ， 再去byName
		 *
		 * Resource byName
		 *
		 */
//		ApplicationContext factory = new ClassPathXmlApplicationContext("classpath:applicationContext.xml");

		AnnotationConfigApplicationContext acont2 = new AnnotationConfigApplicationContext(SpringIOCSong.class);

		/**
		 * 场景： @profile  先不要初始化SpringIOCSong ， 创建一个空的之后，然后设置属性再初始化
		 */
		AnnotationConfigApplicationContext acont = new AnnotationConfigApplicationContext();
//		acont.register(SpringIOCSong.class);
		//插手了spring的初始化过程
//		acont.addBeanFactoryPostProcessor(new MyBeanFactoryPostProcessor());
//		acont.addBeanFactoryPostProcessor(new MyBeanDefinitionRegistryPostProcessor());

		acont.scan("com.song.ioc.循环依赖");
		acont.refresh(); // 一定要调用

		B bean = acont.getBean(B.class);
		bean.testA.testB.testA.testMethodAAAAA();




		/**
		 * 动态开关代理
		 */
//		IImportServiceTest testBean = (IImport ServiceTest) acont.getBean("myImportServiceTest");
//		testBean.test();

//		IUserService iUserService1 = (IUserService) acont.getBean("userServiceTwoImpl");
//		IUserService iUserService2 = (IUserService) acont.getBean("userServiceTwoImpl");
//		System.out.println(iUserService1.hashCode()+"=========="+iUserService2.hashCode());

		// service 中的bean，是id ， @Service 默认的是该类的类名，第一个字母小写。
//		IUserService iUserService = (IUserService) acont.getBean("userServiceImpl");
//		iUserService.sout();

//		System.out.println();

//		IPersonService personServiceimpl = (IPersonService) acont.getBean("personServiceimpl");
//		personServiceimpl.say();







//		ApplicationContext factory = new ClassPathXmlApplicationContext("classpath:applicationContext.xml");


	}

}

